
#include	"wbsinker_error.hpp"
#include	"fifo_storage.hpp"


const char*		sg_pszSinkerConfig = NULL;

void	test_one ( void );

int		main ( void )
{

	sg_pszSinkerConfig = "config.wbsinker";

	test_one ();
	
	return	0;
}

////////////////////////////////////////////////////////////////////////

void	test_one ( void )
{
	FifoStorage	sinker( sg_pszSinkerConfig );
	
	int	iReturn = sinker.open();
	if (iReturn < 0)
	{
		ERROR ( CAT_SINKER, 0, "fail to open with configure '%s'.", sg_pszSinkerConfig );
	}
	
	const char*	ppszKeys[] = {
		"http://www.google.com",
		"http://www.google.com:80",
		"http://www.google.com/",
		"http://www.google.com/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
		"http://www.google.com:80/",
		"http://www.google.com:80/BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
		"http://www.google.com/abc",
		"http://www.google.com:80/abc",
		"ftp://www.google.com:80/",
		"ftp://www.google.com:80/CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC",
		"ftp://www.google.com",
		"www.google.com",
		NULL
	};

	DEBUG ( CAT_SINKER, "------ %s() begin ------", __func__ );
	INFO ( CAT_SINKER, "------ %s() begin ------", __func__ );

	for ( int r=0; r<3200000; r++ ) {
		for ( int i=0; NULL != ppszKeys[i]; i++ ) {
			const char*	pszKey = ppszKeys[ i ];
			try 
			{
				unsigned	iType = strlen(pszKey) * 10;
				//INFO ( CAT_SINKER, "sinking  type=%u data='%s'.", iType, pszKey );
				sinker.write( iType, pszKey, strlen(pszKey) );
			}
			catch ( std::exception& ex ) 
			{
				ERROR ( CAT_SINKER, 0, "map '%s' exception : %s.", pszKey, ex.what() );
			}
		}
	}
	INFO ( CAT_SINKER, "------ %s()   end ------", __func__ );
	DEBUG ( CAT_SINKER, "------ %s()   end ------", __func__ );
	
	sinker.close();
}


////////////////////////////////////////////////////////////////////////

